import java.util.ArrayList;
import java.util.List;

/**
 * @USER: Administrator
 * @DATE: 2024/9/19 下午8:32
 * @VERSION: 1.0.0
 */
public class LC682 {
    public int calPoints(String[] operations) {
        List<Integer> integers = new ArrayList<>();
        int sum=0;
        for (String operation : operations) {
            switch (operation) {
                case "C":
                    integers.remove(integers.size()-1);
                    break;
                case "D":
                    integers.add(integers.get(integers.size()-1)*2);
                    break;
                case "+":
                    integers.add(integers.get(integers.size()-1)+integers.get(integers.size()-2));
                    break;
                default:
                    integers.add(Integer.valueOf(operation));
            }
        }

        for (Integer integer : integers) {
            sum+=integer;
        }
        return sum;
    }
}
